package com.mall.seckill.controller;

import com.alibaba.fastjson.JSON;
import com.common.utils.R;
import com.mall.seckill.dto.SeckillSkuRedisDto;
import com.mall.seckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/seckill")
public class SeckillController {
    @Autowired
    private SeckillService seckillService;
    @GetMapping("/currentSeckillSessionSkus")
    public R getCurrents(){
        List<SeckillSkuRedisDto> skus = seckillService.getCurrentSkus();
        return R.ok().put("data", JSON.toJSONString(skus));
    }
    @GetMapping("/secckillSessionBySkuId/{skuId}")
    public R getSecckillSessionBySkuId(@PathVariable("skuId") Long skuId){
        SeckillSkuRedisDto dto = seckillService.getSecckillSessionBySkuId(skuId);
        return R.ok().put("data",JSON.toJSONString(dto));
    }
}
